﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ASmile.ORM.BuildSQLText
{
    class BuildOleDb : BuildSQLBase
    {
        protected internal override string ParamSignStr => "@";

        public override ISqlBuilder BuildQueryPager(string tableName, string[] fields, int pageNo, int onePage)
        {
            StringBuilder sql = new StringBuilder();
            string selectFields = GetSelectFieldStr(fields);
            sql.AppendFormat("Select Top {0} {1} From {2}", onePage, selectFields, tableName);
            string pkName = fields[0];
            pkName = FormatName(pkName);
            tableName = FormatName(tableName);
            sql.AppendFormat("WHERE {0} NOT IN ( ", pkName);
            sql.AppendFormat("SELECT TOP ({0}*({1}-1)) {2} FROM {3} ", onePage, pageNo, pkName, tableName);
            sql.Append("Where {0} "); //where预留
            sql.Append("Order By {1}"); //order by 预留
            sql.Append(")");
            ISqlBuilder result = CreateBuildResult();
            result.AddSQLText(sql.ToString());
            return result;
        }
    }
}
